import 'dart:math';

import 'package:any_reader/config/resource_manager.dart';
import 'package:any_reader/public.dart';

class SearchItem extends StatelessWidget {
  final Book item;
  final List<Book> list;
  final SearchBookModel model;
  final int index;
  SearchItem({Key key, @required this.item, this.model, this.list, this.index})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
        margin: EdgeInsets.fromLTRB(10, 5, 10, 0),
        decoration: index == list.length - 1
            ? BoxDecoration()
            : BoxDecoration(
                border: new Border(
                    bottom: BorderSide(
                        color: model
                            .themeModel.customThemeData.mainBackgroundColor,
                        width: 0.5))),
        child: InkWell(
            onTap: () {
              String title = Uri.encodeComponent(item.title) ?? "";
              String url = Uri.encodeComponent(item.url) ?? "";
              String author = Uri.encodeComponent(item.author) ?? "";
              String reptileType = Uri.encodeComponent(item.reptileType) ?? "";
              String reptileType1 =
                  Uri.encodeComponent(item.reptileType1) ?? "";
              var route = "/book_info?"
                  "title=$title&"
                  "author=$author&"
                  "url=$url&"
                  "now=0&"
                  "reptileType=$reptileType&"
                  "reptileType1=$reptileType1&";
              AppConfig.router.navigateTo(context, route,
                  transition: TransitionType.inFromRight);
            },
            child: new SizedBox(
              height: ScreenUtil().setHeight(250),
              child: Row(
                children: <Widget>[
                  new Expanded(
                    flex: 1,
                    child: Padding(
                      padding: EdgeInsets.all(0),
                      child: item.imgUrl != "" && item.imgUrl != null
                          ? CachedImage(
                              url: item.imgUrl ?? "",
                            )
                          : Image.asset(
                              ImageHelper.wrapAssets('default_cover.jpg')),
                    ),
                  ),
                  new Expanded(
                      flex: 3,
                      child: Padding(
                          padding: EdgeInsets.all(10),
                          child: Column(
                            children: <Widget>[
                              Row(children: <Widget>[
                                Text(
                                  item.title + "",
                                  style: TextStyle(
                                      fontSize: 18, color: Color(0xFF747474)),
                                ),
                              ]),
                              Row(children: <Widget>[
                                Text(item.author + "",
                                    style: TextStyle(
                                        fontSize: 14,
                                        color: Color(0xFFf88a3f))),
                              ]),
                              Row(
                                children: <Widget>[
                                  Container(
                                    child: Text(
                                      item.description ?? "暂无简介",
                                      maxLines: 5,
                                      softWrap: true,
                                      overflow: TextOverflow.ellipsis,
                                      textAlign: TextAlign.left,
                                      style: new TextStyle(
                                          fontSize: 12,
                                          color: Color(0xFF686868)),
                                    ),
                                    width: ScreenUtil().setWidth(750 * 0.6),
                                  )
                                ],
                              ),
                            ],
                          )))
                ],
              ),
            )));
  }
}
